import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Page 		= $Lazy.load(()=>import('#tp/page/page-container'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		// 搜索表单列表
		forms : [
			{ label: '编号',		name: 'code' },
			{ label: '名称',		name: 'name' },
			{ label: '类型 ',	name: 'type' }
		],
	}
	
	model = {}
	
	componentDidMount(){
		this.fetch()
		$fn.fresh.on(this.getSelect)
	}
	
	componentWillUnmount(){
		$fn.fresh.remove()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'conf-data-convert/index')
	
	// 表单
	cols = [
		{ title: '编号', 		dataIndex: 'code', 			width:150 },
		{ title: '名称', 		dataIndex: 'name', 			width:250 },
		{ title: '类型', 		dataIndex: 'type', 			width:100 },
		{ title: '时间', 		dataIndex: 'update_at', 	width:200 },
		{ title: '描述', 		dataIndex: 'description', 	width:100 },
		{ title: '是否启用', 	dataIndex: 'status', 		...$fn.table.num, render: text => +text === 1 ? '是' : '否'  },
		TableControls.controls.call(this,{ width: 400 })
	]
	// 表格操作按钮
	table_controls = (text,{uuid, device_id, device_name}) => {
		return [
			TableControls.pushTo.call(this, '编辑', `device-add?uuid=${uuid}`),
		]
	}
	// 操作按钮
	controls = () => [
		Controls.pushTo.call(this, '添加', 'device-add' ),
		Controls.exports.call(this, 'conf-data-convert/index'),
	]
	
	render(){
		return (
			<Page title='三方联接' controls={this.controls()}>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this) }
			</Page>
		)
	}
}

export default Index